package com.shujia.flink.window

import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.assigners.{SlidingProcessingTimeWindows, TumblingProcessingTimeWindows}
import org.apache.flink.streaming.api.windowing.time.Time

object Demo1TImeWindow {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment


    val ds1: DataStream[String] = env.socketTextStream("master", 6666)

    val kvDS: DataStream[(String, Int)] = ds1.flatMap(_.split(","))
      .map((_, 1))


    /**
      * TumblingProcessingTimeWindows   滚动的处理时间窗口
      * TumblingEventTimeWindows  滚动的事件事件窗口
      *
      * SlidingProcessingTimeWindows  滑动的处理时间窗口
      * SlidingEventTimeWindows  滑动的事件时间窗口
      */


    kvDS.keyBy(_._1)
      //      .timeWindow(Time.seconds(5))
      .window(SlidingProcessingTimeWindows.of(Time.seconds(5), Time.seconds(1)))
      .sum(1)
      .print()


    env.execute()


  }
}
